package com.mst.service.Impl;

import com.mst.dao.UserDao;
import com.mst.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
//1.全参构造实现依赖注入
//@AllArgsConstructor
public class UserServiceImpl implements IUserService {
    //        2.将注解加在参数上实现依赖注入
    @Autowired
//   Qualifier 开启指定名称装配bean,必须配合Autowired使用
//    @Qualifier("userD2")
//    Resource 默认通过属性名寻找
    @Resource(name = "userD2")
    private UserDao userDao;
    @Value("root")
    private String username;
    @Value("${jdbc.password}")
    private String password;
//    private UserDao userDao;

    //    3.在set方法上添加Autowired实现注入
//    @Autowired
//    public void setUserDao(UserDao userDao) {
//        this.userDao = userDao;
//    }
//    4.在构造方法上添加Autowired ,Autowired可以省略
//    @Autowired
//    public UserServiceImpl(UserDao userDao) {
//        this.userDao = userDao;
//    }

    @Override
    public void print() {
        System.out.println(username);
        System.out.println(password);
        userDao.print();
    }
}
